﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace Nova_DAL
{
    public class Role
    {
        string strSQL = "";
        int i = 0;
        DbHelper dbHelper = new DbHelper();
        string ScaRole = "";

        ///<summary>
        ///返回记录集
        ///</summary>
        ///<param name="vGroupNo">vGroupNo</param>
        ///<returns>返回字符串</returnss>
        ///Writer：[王成友]
        ///Create Date： [2010-5-27]
        ///</summary>
        public string ScalarRole(string vGroupNo)
        {
            try
            {
                strSQL = "select vPermit from tbGroupPermit where vGroupNo=@vGroupNo";
                DbCommand cmd = dbHelper.GetSqlStringCommond(strSQL);
                cmd = dbHelper.GetSqlStringCommond(strSQL);
                dbHelper.AddInParameter(cmd, "@vGroupNo", DbType.String, vGroupNo);
                ScaRole = (string)dbHelper.ExecuteScalar(cmd);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return ScaRole;
        }


        ///<summary>
        ///增加工作组编号对应的权限列表(菜单ID)
        ///</summary>
        ///<param name="Role">Role</param>
        ///<returns>0.失败，1.成功</returnss>
        ///Writer：[王成友]
        ///Create Date： [2010-5-27]
        ///</summary>
        public int AddRole(Nova_MOD.Role Role)
        {
            try
            {
                strSQL = "insert tbGroupPermit(vPermit,vGroupNo) values(@vPermit,@vGroupNo)";
                DbCommand cmd = dbHelper.GetSqlStringCommond(strSQL);
                dbHelper.AddInParameter(cmd, "@vPermit", DbType.String, Role.vPermit);
                dbHelper.AddInParameter(cmd, "@vGroupNo", DbType.String, Role.vGroupNo);
                i = dbHelper.ExecuteNonQuery(cmd);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return i;
        }

        ///<summary>
        ///修改工作组编号对应的权限列表(菜单ID)
        ///</summary>
        ///<param name="Role">Role</param>
        ///<returns>0.失败，1.成功</returnss>
        ///Writer：[王成友]
        ///Create Date： [2010-5-27]
        ///</summary>
        public int UpdateRole(Nova_MOD.Role Role)
        {
            try
            {
                strSQL = "update tbGroupPermit set vPermit = @vPermit where vGroupNo = @vGroupNo";
                DbCommand cmd = dbHelper.GetSqlStringCommond(strSQL);
                dbHelper.AddInParameter(cmd, "@vPermit", DbType.String, Role.vPermit);
                dbHelper.AddInParameter(cmd, "@vGroupNo", DbType.String, Role.vGroupNo);
                i = dbHelper.ExecuteNonQuery(cmd);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return i;
        }

    }
}
